package com.yihu.cms.util;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.yihu.article.beans.Article;
import com.yihu.article.beans.LoginResult;
import com.yihu.beans.Artwork;

public class CommonUtils {

	public static Map<String, Object> getResult(int resultCode, 
			Object info) {
		String message = "";
		if (resultCode == 0)
			message = "success";
		else
			message = "fail";

		Map<String, Object> mapResult = new HashMap<String, Object>();
		mapResult.put("result", resultCode);
		mapResult.put("message", message);
		mapResult.put("info", info);
		return mapResult;
	}
	
	public static Map<String, Object> getResult(int resultCode, int errorCode) {
		Map<String, Object> mapResult = new HashMap<String, Object>();
		String message = "";
		if (resultCode == 0)
			message = "success";
		else{
			mapResult.put("errorCode", errorCode);
			message = "fail";
		}
		mapResult.put("result", resultCode);
		mapResult.put("message", message);
		return mapResult;
	}
	
	public static Map<String, Object> getResult(String result, 
			Object info) {
		String message = "";
		int resultCode = 0;
		if (!InfoHelp.isBlank(result))
			message = "success";
		else{
			message = "fail";
			resultCode = 1;
		}
			

		Map<String, Object> mapResult = new HashMap<String, Object>();
		mapResult.put("result", resultCode);
		mapResult.put("message", message);
		LoginResult lr = JSON.parseObject(result, LoginResult.class);
		mapResult.put("userId", lr.getUserId());
		mapResult.put("info", info);
		return mapResult;
	}
	
	
	public static void main(String[] args) {
		//JSON.parseObject(artworkJson, Artwork.class)
		Article a = new Article();
		a.setTitle("1234");
		String s = JSON.toJSONString(a);
		System.out.println(s);
	}
}
